package 正则表达式.爬虫;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class 文本爬虫 {
    public static void main(String[] args) {
        String str="Sure! Here’s a short paragraph in English that includes several instances of" +
                " the word name In the bustling town of Willow Creek, everyone knew" +
                " the name1 of the famous baker, Alice. Her pastries were so delicious " +
                "that people would often stop by just to say her name. One day, a new café " +
                "opened, and its owner, John, wanted to make a name2 for himself as well. He believed " +
                "that if he could impress Alice with his coffee, she might mention his name5 to her " +
                "loyal customers. As the sun set over the town, both Alice and John hoped to carve out " +
                "their names in the hearts of the people.If you need any adjustments or have other requests, " +
                "feel free to let me know!";

        // 1.获取正则表达式的对象
        Pattern p=Pattern.compile("name\\d{0,1}");
        // 2.获取文本匹配器的对象
        Matcher m=p.matcher(str);

        while(m.find()){
            System.out.println(m.group());
        }

    }
}
